package com.thread.test2;

/**
 * @description: TODO 类描述
 * @author: YUANG
 * @date: 2022/3/7
 **/
public class InterruptTest {
    public static void main(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();
        Thread.sleep(3);
        t.interrupt();
        //main 会进入等待状态,如果此时对main interrupt main会报出 InterruptException
        //目标线程监控InterruptException ,捕捉到时,就代表有其他线程调用了他的中断,通常情况下,该线程应该立刻停止
        t.join();
        System.out.println("main end");
    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        int n = 0;
        while (!isInterrupted()) {
            n++;
            System.out.println(n);
        }
        System.out.println("san end");
    }
}
